import { defineStore } from 'pinia'
import { TableListItem } from './data.d';
import {
	queryList,
	removeData,
	createData,
	updateData,
} from './service';

export const useTableStore = defineStore('TableStore', {
	state: () => {
		return {
			list: []
		}
	},
	actions: {
		async queryTableData(site) {
			let params={
				id:site
			}
			this.list = await queryList(params);

		},
		async deleteTableData(id: number) {
			try {
				const response = await removeData(id)
				return true
			} catch (error) {
				return false
			}

		},
		async createTableData(params: TableListItem) {
			try {
				const response = await createData(params)
				return true
			} catch (error) {
				return false
			}
		},
		async updateTableData(params: TableListItem) {
			try {
				const response = await updateData(params)
				console.log('response',response)
				return true
			} catch (error) {
				return false
			}
		}
	}
})